package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.acticle.domain.Destination;
import cn.wolfcode.luowowo.acticle.domain.Region;
import cn.wolfcode.luowowo.acticle.query.DestinationQueryObject;
import cn.wolfcode.luowowo.acticle.query.RegionQueryObject;
import cn.wolfcode.luowowo.acticle.service.IDestinationService;
import cn.wolfcode.luowowo.acticle.service.IRegionService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 区域控制器
 */
@Controller
@RequestMapping("/region")
public class RegionController {
    @Reference
    private IRegionService regionService;
    @Reference
    private IDestinationService destinationService;
    //列表功能
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQueryObject qo){
        PageInfo pageInfo = regionService .query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "region/list";
    }

    //根据deep获取地区
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public List<Destination> getDestByDeep(DestinationQueryObject qo){
        return destinationService.getDestinationByDeep(3);
    }

    //新增和更新
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){
        regionService.saveOrUpdate(region);
        return new AjaxResult();
    }

    //根据区域id获取地区
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(Long rid){
        return destinationService.getDestinationByRegionId(rid);
    }

    //修改区域状态
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(Integer hot, Long id){
        regionService.changeHotValue(hot, id);
        return new AjaxResult();
    }

    //删除区域(真实情况只会修改状态不会删除)
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        regionService.delete(id);
        return new AjaxResult();
    }
}
